package com.tiancheng.trade.order.service;

import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.commom.core.exception.BusinessException;
import com.tiancheng.trade.order.bo.*;
import com.tiancheng.trade.order.model.IntOrder;
import com.tiancheng.trade.order.model.join.IntOrderJoin;
import com.tiancheng.trade.order.vo.admin.QueryOrdersVO;
import com.tiancheng.trade.order.vo.admin.res.OrderDetailResVO;
import com.tiancheng.trade.order.vo.admin.res.OrderResVO;
import com.tiancheng.trade.order.vo.api.CloseOrderVO;
import com.tiancheng.trade.order.vo.api.RefundVO;
import com.tiancheng.trade.order.vo.api.res.CreateOrderResVO;
import com.tiancheng.trade.order.vo.api.res.PaypalQueryResVO;
import com.tiancheng.trade.order.vo.api.res.RefundCreateResVO;
import com.tiancheng.trade.order.vo.app.*;
import com.tiancheng.trade.order.vo.app.res.*;

import java.util.List;
import java.util.Set;

/**
 * 订单Service接口
 */
public interface IntOrderService {

    /**
     * 创建订单（主订单、子订单、优惠券）
     *
     * @param orderBO
     * @param subOrderBOS
     * @return
     * @throws BusinessException
     */
    String create(OrderBO orderBO, List<SubOrderBO> subOrderBOS) throws BusinessException;
    /**
     * 创建订单（主订单、子订单、优惠券）
     *
     * @param orderBO
     * @param subOrderBOS
     * @return
     * @throws BusinessException
     */
    CreateOrderResVO createOrder(OrderBO orderBO, List<SubOrderBO> subOrderBOS) throws BusinessException;

    /**
     * 关闭订单
     *
     * @param closeOrderVO
     * @return
     * @throws BusinessException
     */
    boolean closeOrder(CloseOrderVO closeOrderVO) throws BusinessException;

    /**
     * 创建paypal支付订单
     *
     * @param uid
     * @param reqVO
     * @return
     * @throws BusinessException
     */
    PaypalCreateResVO createPaypal(String uid, PaypalCreateReqVO reqVO) throws BusinessException;


    PaypalExecuteResVO executePaypay(String uid, PaypalExecuteReqVO reqVO)throws BusinessException;


    /**
     * 创建并提交退款
     * @param refundVO
     * @return
     * @throws BusinessException
     */
    RefundCreateResVO refundOrder(RefundVO refundVO) throws BusinessException;

    /**
     * 查询指定订单
     *
     * @param uid
     * @param orderId
     * @return
     */
    IntOrder get(String uid, String orderId);

    /**
     * 根据订单号查询主订单及子订单数据
     *
     * @param orderId
     * @return
     */
    IntOrderJoin findByOrderId(String orderId);

    /**
     * 保存支付通知结果
     *
     * @param intPayNotifyBO
     * @throws BusinessException
     */
    void savePayResult(IntPayNotifyBO intPayNotifyBO) throws BusinessException;


    /**
     * 根据订单号查询
     *
     * @param orderId
     * @return
     */
    IntOrder get(String orderId);

    /***
     * 移动端查询订单列表
     * @param orderQueryVO
     * @return
     */
    PageInfo<IntOrderQueryResVO> findForApp(OrderQueryVO orderQueryVO);


    /**
     * 查询paypal支付信息
     * @param orderId
     * @return
     */
    Result<PaypalQueryResVO> getPaypalInfo(String orderId);

    /**
     * 根据主键id查询主订单详情
     *
     * @param orderId
     * @return
     */
    OrderDetailResVO queryOrderDetailsByOrderId(String orderId);

    /**
     * 主订单查询分页
     *
     * @param orderVO
     * @return
     */
    PageInfo<OrderResVO> queryOrderList(QueryOrdersVO orderVO);

    /**
     * 查询
     *
     * @param uid
     * @param orderIds
     * @return
     */
    List<IntOrder> find(String uid, String[] orderIds);

    /**
     * 退款
     *
     * @param success
     * @param orderId
     * @param subOrderRefundBOS
     * @return
     */
    int refund(boolean success, String orderId, List<SubOrderRefundBO> subOrderRefundBOS);



    /**
     * 根据流水号查询主订单及子订单数据
     *
     * @param flowId
     * @return
     */
    List<IntOrderJoin> findWithSubByFlowId(String flowId);


    /**
     * 获取订单的支付状态
     *
     * @param uid
     * @param orderId
     * @return
     */
    String getPayStatus(String uid, String orderId) throws BusinessException;

    /**
     * 根据主订号查询单
     *
     * @param orderIds
     * @return
     */
    List<IntOrder> findByOrderIds(Set<String> orderIds);


    /**
     * 英文版APP初始化收银台
     *
     * @param uid
     * @param reqVO
     * @return
     */
    IntCashierResVO initCashier(String uid, IntCashierReqVO reqVO) throws BusinessException;

    /*处理支付结果*/
    void intPayResult(IntPayNotifyBO intPayNotifyBO) throws BusinessException;

}
